// const OSS = require('ali-oss');

// const client = new OSS({
//   // 填写Bucket所在地域。以华东1（杭州）为例，Region填写为oss-cn-hangzhou。
//   region: 'oss-cn-hangzhou',
//   // 阿里云账号AccessKey拥有所有API的访问权限，风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维，请登录RAM控制台创建RAM用户。
//   accessKeyId: 'LTAI5tLtM45v4t7Fvuc5eGMR',
//   accessKeySecret: 'INMQV9x4AJ9zYTRpuDK3Syjqj6UnIb',
//   // 填写存储空间名称。
//   bucket: 'xiangyunwx'
// })

// export const signUrl = (url) => {
// 	return client.signatureUrl(url, {expires: 3600}
// 	)}
export const setStorageSync = (key,value) => {
	try {
		uni.setStorageSync(key, value);
	} catch (e) {
		// error
	}
}

export const getStorageSync = (key) => {
	// return new Promise((resolve, reject) => {
		try {
			const value = uni.getStorageSync(key);
			return value || ''
		} catch (e) {
			// error
			reject('获取失败')
		}
	// })
	
}

export const removeStorageSync = (key) => {
	try {
		uni.removeStorageSync(key);
	} catch (e) {
		// error
	}
}

export const clearStorageSync = () => {
	try {
		uni.clearStorageSync();
	} catch (e) {
		// error
	}
}

export const callPhone = (phoneNumber) => {
	uni.makePhoneCall({
	  phoneNumber: phoneNumber, // 电话号码
	  success: function () {
	    console.log('拨打电话成功');
	  },
	  fail: function () {
	    console.log('拨打电话失败');
	  }
	});
	return;
      // 判断是否为字符串，并且是否为纯数字
      if (typeof phoneNumber === 'string' && /^\d+$/.test(phoneNumber)) {
       
      } else {
        console.log('电话号码不正确');
		uni.showToast({
			icon:'none',
			title:'电话号码不正确'
		})
      }
    }

export const uploadFile = () => {
	return new Promise((resolve, reject) => {
		uni.chooseImage({
			count: 1,
			mediaType: ['image'],
			sourceType: ['album', 'camera'],
			camera: 'back',
			success:(files) => {
				uni.showLoading({
					title:'上传中……',
					mask: true
				})
				uni.uploadFile({
					url: 'https://myxiangyu.com/file/upload', 
					filePath: files.tempFiles[0].path,
					name: 'file',
					success: (uploadFileRes) => {
						if(uploadFileRes.data){
							const data = JSON.parse(uploadFileRes.data)
							resolve(data.data)
						}
					},
					complete:() => {
						uni.hideLoading()
					}
				});
			}
			})
	})
	
}
